package com.yunban.project.article.controller;

import com.yunban.project.article.model.dto.ArticleReq;
import com.yunban.project.article.model.dto.ArticleSearchReq;
import com.yunban.project.article.model.vo.ArticleResp;
import com.yunban.project.article.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import net.lab1024.sa.base.common.domain.PageResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@Tag(name = "文章模块-解析历史记录")
@RequestMapping("/article-api")
public class ArticleController {
    @Resource
    private ArticleService articleService;

    @PostMapping
    @Operation(summary = "保存文章")
    Long saveArticle(@RequestBody @Validated ArticleReq req) {
        return this.articleService.saveArticle(req);
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取文章详情")
    ArticleResp getArticleDetail(@PathVariable long id) {
        return this.articleService.getArticleDetail(id);
    }

    @PostMapping("/search")
    @Operation(summary = "获取文章列表")
    PageResult<ArticleResp> getArticleList(@RequestBody ArticleSearchReq req) {
        return this.articleService.getArticleList(req);
    }

    @PostMapping("/{id}/publish")
    @Operation(summary = "发表文章")
    Boolean publishArticle(@PathVariable long id) {
        return this.articleService.publishArticle(id);
    }

    @PostMapping("/{id}/cancel/publish")
    @Operation(summary = "取消发表")
    Boolean cancelPublishArticle(@PathVariable long id) {
        return this.articleService.cancelPublishArticle(id);
    }
}
